package com.api.oa.mapper;

import com.api.oa.model.entity.YQInsPatientHis;
import com.api.oa.model.vo.OaNoticeVo;
import com.api.oa.model.vo.YQUserVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface YQInsPatientHisMapper {

    @Insert("insert into  yq_ins_patient_history  (" +
            "historyId," +
            "insCode," +
            "patientIdCard," +
            "createdAt" +
            ") " +
            "values " +
            "(" +
            "#{entity.historyId}," +
            "#{entity.insCode}," +
            "#{entity.patientIdCard}," +
            "#{entity.createdAt}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "historyId", keyColumn = "id")
    Integer insert(@Param("entity") YQInsPatientHis entity);


    @Update("update  yq_ins_patient_history  set " +
            "historyId = #{entity.historyId}," +
            "insCode = #{entity.insCode}," +
            "patientIdCard = #{entity.patientIdCard}" +
            " where historyId = #{entity.historyId}")
    Integer update(@Param("entity") YQInsPatientHis entity);


    @Delete("delete from yq_ins_patient_history where historyId=#{id}")
    void delete(@Param("id") Long id);


    @Select("select * from  yq_ins_patient_history  where historyId = #{id}")
    List<YQInsPatientHis> list(@Param("id") Long pid);


    @Select("select * from  yq_ins_patient_history  where historyId = #{id} limit 1")
    YQInsPatientHis findOne(@Param("id") Long id);


    //机构下的有人脸的患者
    @Select("<script>SELECT v_yq_patient_user.*,yq_user_face.userId as face FROM yq_user_face right join v_yq_patient_user on yq_user_face.userId = v_yq_patient_user.userId" +
            " where v_yq_patient_user.attendType = #{attendType} and patientIns =#{insCode} and yq_user_face.user is null </script>")
    List<YQUserVO> queryNoRecordFace(String insCode, String attendType);


    //机构下的没有录入人脸的患者
    @Select("<script>SELECT v_yq_patient_user.*,yq_user_face.userId as face FROM yq_user_face right join v_yq_patient_user on yq_user_face.userId = v_yq_patient_user.userId" +
            " where v_yq_patient_user.attendType = #{attendType} and patientIns =#{insCode} and yq_user_face.user is not null </script>")
    List<YQUserVO> queryHasRecordFace(String insCode, String attendType);

}

